﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dominio;
using FluentNHibernate.Mapping;
using FluentNHibernate;

namespace Infra.NHibernateFramework {
    public class UsuarioMap : ClassMap<Usuario>{
        public UsuarioMap() {
            Id(x => x.Id, "IdUsuario").GeneratedBy.Identity();

            Map(x => x.Nome)
                .Not.Nullable()
                .Length(100);

            HasMany(x => x.Contas)
                .KeyColumn("IdUsuario")
                .Fetch.Join()                
                .Inverse()
                .Cascade.AllDeleteOrphan()
                .LazyLoad()
                .AsBag().Cache.ReadWrite();

            HasMany(x => x.Categorias)
                .KeyColumn("IdUsuario")
                .Inverse()
                .Cascade.AllDeleteOrphan()
                .LazyLoad()
                .AsBag();

            Cache.ReadWrite();
        }
    }
}
